/**
 * The Community Project
 * Copyright Team1 Productions
 * 
 * Joshua Amick
 * Stephen Cunningham
 * Thema Davis
 * Tomika Dawson
 * Lucie DeCristofaro
 * 
 * All Rights Reserved.
 */

package com.dao;

import java.sql.Timestamp;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Expression;

import com.domain.Profile;
import com.domain.User;

public class ProfileDAO extends BaseObjectDAO{
	
	public Profile save(Profile profile){
		Timestamp now = new Timestamp(System.currentTimeMillis());
		profile.setLastModDate(now);
		this.getSession().saveOrUpdate(profile);
		this.getSession().flush();
		if((profile.getKeyId()!=null)){
			return profile;
		}
		else return null;
	}
	
	public User saveProfile(User user, String firstName, String lastName, String address1, String address2,
			String city, String State, String zip, String secondaryEmail, String phone, String employer, 
			String positionDescription, Timestamp employmentStartDate, String education, String major, Timestamp graduationDate,
			String professionalOrganizations, String studentOrganizations, boolean publicViewable){
		
		
		
		return null;
	}
	
	public Profile buildProfile(String firstName, String lastName, String address1, String address2,
			String city, String state, String zip, String secondaryEmail, String phone, String employer, 
			String positionDescription, Timestamp employmentStartDate, String education, String major, Timestamp graduationDate,
			String professionalOrganizations, String studentOrganizations, boolean publicViewable){
		
		Profile profile = new Profile();
		
		profile.setFirstName(firstName);
		profile.setLastName(lastName);
		profile.setAddress1(address1);
		profile.setAddress2(address2);
		profile.setCity(city);
		profile.setState(state);
		profile.setZip(zip);
		profile.setSecondaryEmail(secondaryEmail);
		profile.setPhone(phone);
		profile.setEmployer(employer);
		profile.setPositionDescription(positionDescription);
		profile.setEmploymentStartDate(employmentStartDate);
		profile.setEducation(education);
		profile.setMajor(major);
		profile.setGraduationDate(graduationDate);
		profile.setProfessionalOrganizations(professionalOrganizations);
		profile.setStudentOrganizations(studentOrganizations);
		profile.setPublicViewable(publicViewable);
		
		return profile;
	}

	public Profile getProfileByKeyId(Long keyId) {
		Profile profileToSave = null;
		if((keyId!=null)&&(keyId>0)){
			Criteria crit = this.getSession().createCriteria(Profile.class);
			crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
	       	crit.add(Expression.eq("keyId",keyId));
	       	List<Profile> results = crit.list();
	       	profileToSave = results.get(0);
		}
		return profileToSave;
	}
}
